﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

using NUnit.Framework;

using Microsoft.Practices.Unity;

namespace ERPStore.Payments.Direct.Tests.Controllers
{
	[TestFixture]
	public class WireTransferPaymentControllerTests : ERPStore.Tests.TestBase
	{
		[SetUp]
		public override void Initialize()
		{
			base.Initialize();

			GlobalConfiguration.Configuration.Settings.Payment.AllowedPaymentList.Add("Check");
			GlobalConfiguration.Configuration.Settings.Payment.AllowedPaymentList.Add("WireTransfer");
			GlobalConfiguration.Configuration.Settings.Payment.AllowedPaymentList.Add("DeferredPayment");
		}

		[Test]
		public void Finalized_With_Wrong_Key()
		{
			var wireTransferController = CreateAuthenticatedController<ERPStore.Payment.Direct.Controllers.CheckPaymentController>();
			var finalizedResult = wireTransferController.Finalized("badkey") as System.Web.Mvc.RedirectToRouteResult;

			Assert.AreEqual(finalizedResult.RouteName, ERPStore.Web.Routing.ERPStoreRoutes.HOME);
		}

		[Test]
		public void Finalize_Anonymous()
		{
			var wireTransferController = CreateController<ERPStore.Payment.Direct.Controllers.WireTransferPaymentController>();
			Assert.AreEqual(true, ControllerActionInvoker<HttpUnauthorizedResult>().InvokeAction(wireTransferController.ControllerContext, "Finalized"));
		}

		[Test]
		public void Finalize_With_Empty_Cart()
		{
			var wireTransferController = CreateAuthenticatedController<ERPStore.Payment.Direct.Controllers.WireTransferPaymentController>();
			var checkoutController = CreateAuthenticatedController<ERPStore.Checkout.Controllers.CheckoutController>();

			var result = wireTransferController.Finalized(null) as RedirectToRouteResult;
			Assert.AreEqual(result.RouteName, ERPStore.Web.Routing.ERPStoreRoutes.HOME);
		}

	}
}
